home *** CD-ROM | disk | FTP | other *** search
- ******************************************************************
- * COPYRIGHT (C) 1986 by Donald Krantz and James Stanley
- * - Note: This is a real, live, actual, registered copyright,
- * and should be treated as such. This source code is from
- * the book "68000 Assembly Language", Krantz and Stanley,
- * Addison-Wesley Publishing Company, Reading, MA, 1986.
- *
- * Permission granted by the authors for non-commercial use
- * in programs released to the public domain, as long as this
- * copyright notice remains attached and visible.
- *
- *****************************************************************
- * EDIT2 - Screen printer. Updates the display after each cursor
- * move or file modification.
-
- xref cursor,putc,printf
- xdef prtscr,exp_chr,stats,set_edit,cmd_w
-
- #edit.h
-
- *****************************************************************
- * PRTSCR - Prints screen from A5
- prtscr:
- movem.l d1-d5/a0,-(a7)
- redo:
- move.l top_lef(a5),a0 * get starting character for scrn
- move.w w_ulcy(a5),d3 * d3 is screen row number
- row_loop:
- move.w w_ulcx(a5),d2 * d2 is screen column number
- clr.w d5 * D5 is logical column
- clr.w d4 * D4 is actual column in line
- move.w d3,-(a7) * Push cursor Y base location
- move.w d2,-(a7) * Push cursor X base address
- bsr cursor * setup cursor location
- addq.l #4,a7 * adjust stack
- chr_loop:
- cmp.l b_gap(a5),a0 * Test for gap
- blt sk1_ps * Not at gap, jump by
- cmp.l e_gap(a5),a0 * Are we already past gap?
- bge sk1_ps * Yes, jump by
- move.l e_gap(a5),a0 * move pointer past gap
- move.w d2,scr_col(a5) * save cursor position
- move.w d3,scr_row(a5)
- move.w d5,log_col(a5) * Save logical column
- cmp.w w_off(a5),d4 * are we before window edge?
- bge sk2_ps * nope.
- clr.w w_off(a5) * set offset to zero, redraw
- bra redo
- sk2_ps:
- cmp.w w_lrcx(a5),d2 * are we past window edge?
- ble sk1_ps * no, continue
- sub.w w_lrcx(a5),d4 * subtract difference
- add.w w_ulcx(a5),d4 * add screen offset
- addq.w #8,d4 * add eight for good measure
- add.w d4,w_off(a5) * set window offset, redraw
- bra redo
- sk1_ps:
- cmp.l e_buf(a5),a0 * Test for end of file
- bgt sk0_ps * jump on end of file
- move.b (a0)+,d0 * pick up printable character
- cmp.b #10,d0 * is this a newline?
- beq sk0_ps * if yes, line is complete
- bsr exp_chr * expand character and print
- bra chr_loop * get next char and repeat
- sk0_ps:
- bsr clr_eol * Clear to end of line
- row_tst:
- addq.w #1,d3 * Increment row
- cmp.w w_lrby(a5),d3 * enough lines to fill window?
- blt row_loop * jump back if not.
- move.w scr_row(a5),-(a7) reset cursor to proper location
- move.w scr_col(a5),-(a7)
- bsr cursor * go set cursor
- addq.l #4,a7 * adjust stack
- movem.l (a7)+,d1-d5/a0
- rts
- *****************************************************************
- * EXP_CHR - expands and prints a character
- * D0.B is character to print
- * D5.W is logical screen column, in/out parameter
- * D4.W is column count into line, in/out parameter
- * D2.W is actual screen X position, in/out parameter
- exp_chr:
- cmp.b #$9,d0 * Is this a tab character?
- beq tabs * If so, expand tabs.
- cmp.b #$20,d0 * is this a control char?
- blt control * If so, expand control char
- cmp.w w_off(a5),d4 * are we up to window edge?
- blt sk0_ex * no, skip the printing.
- cmp.w w_lrcx(a5),d2 * are we past window edge?
- bgt sk0_ex * if so, skip printing
- move.w d0,-(a7) * just print regular chars
- bsr putc
- addq.l #2,a7 * adjust stack
- addq.l #1,d2 * add 1 to screen column
- sk0_ex:
- addq.l #1,d5 * add 1 to logical column
- addq.l #1,d4 * add 1 to line's column count
- bra exp_exit * processing complete
- tabs:
- move.b #' ',d0 * expand with spaces
- bsr exp_chr * call recursively
- move.w d5,d1 * get copy of logical column
- and.w #7,d1 * check for tab column stop
- bne tabs * repeat as necessary
- bra exp_exit * leave when done
- control:
- move.w d0,-(a7) * save character
- move.b #'^',d0 * pass a circumflex recursively
- bsr exp_chr * go do it
- move.w (a7)+,d0 * retrieve character
- add.b #$40,d0 * make it printable
- bsr exp_chr * print it out
- subq.w #2,d5 * adjust logical column
- exp_exit:
- rts
- *****************************************************************
- * CLR_EOL - Clears to end of line
- * D2.W is actual screen column
- clr_eol:
- move.w #' ',-(a7) * push spaces
- lp0_el:
- cmp.w w_lrcx(a5),d2 * test if we're at end of window
- bgt sk0_el * if so, we're done
- bsr putc * otherwise, print blank
- addq.w #1,d2 * adjust screen position
- bra lp0_el * and repeat
- sk0_el:
- addq.l #2,a7 * adjust stack (remove blank)
- rts
- *****************************************************************
- * STATS - prints current file stats in command window
- stats:
- movem.l d0/d1/a5,-(a7)
- tst.w insert(a5) * check if insert on or off
- beq no_ins
- move.l #on,-(a7) * push "On" message
- bra past_ins
- no_ins:
- move.l #off,-(a7) * push "Off" message
- past_ins:
- move.l e_gap(a5),d0 * compute space available
- sub.l b_gap(a5),d0
- move.w d0,-(a7)
- move.l b_gap(a5),d0 * compute chars behind cursor
- sub.l b_buf(a5),d0
- move.w d0,-(a7)
- move.w log_col(a5),-(a7) * print logical column
- move.w log_lin(a5),-(a7) * print logical line
- pea fname(a5) * print filename
- move.l #cmd_w,a5 * load up command window desc.
- move.w w_ulcy(a5),-(a7) * push Y position
- add.w #1,(a7) * adjust Y position
- move.w w_ulcx(a5),-(a7) * push X position
- move.l #statstr,-(a7) * push format string address
- bsr printf
- add.l #24,a7 * adjust stack
- movem.l (a7)+,d0/d1/a5
- rts
- statstr:
- dc.b '%vFile: %-14s LN %-5u CO %-5u CH %-5u SP %-5u'
- dc.b ' Insert %-3s',0
- on: dc.b 'On',0
- off: dc.b 'Off',0
- dc.w 0
- *****************************************************************
- * SET_EDIT - initializes edit descriptor file parameters
- set_edit:
- move.l a0,-(a7) * save caller's a0
- clr.w scr_row(a5) * cursor Y address
- clr.w scr_col(a5) * cursor X address
- clr.w ed_err(a5) * edit error flag
- clr.w modify(a5) * file modified flag
- move.l a5,a0 * descriptor base address
- add.l #buffer,a0 * offset to start of char buffer
- move.l a0,b_buf(a5) * buffer start address
- move.l a0,b_gap(a5) * gap starting address
- move.l a0,top_lef(a5) * addr of top left character
- move.l a5,a0 * descriptor base address
- add.l #DESC-1,a0 * add offset to end of buffer
- move.l a0,e_buf(a5) * buffer end address
- addq.l #1,a0 * gap end address
- move.l a0,e_gap(a5) * gap ending address
- clr.l blk_st(a5) * block start address
- clr.l blk_end(a5) * block end address
- clr.l cur_lin(a5) * address 1st char, current line
- clr.w log_lin(a5) * cursor logical line
- clr.w log_col(a5) * cursor logical column
- clr.w w_off(a5) * set offset to 0
- move.w #$FFFF,insert(a5) turn insert toggle on
- move.l (a7)+,a0 * restore caller's a0
- rts
- *****************************************************************
- bss
- cmd_w: ds.b buffer * command I/O window
-
- end